#include "stdafx.h"
#include "Skill.h"
Skill::Skill()
{
	m_nSkillId = 0;
	m_pSkillCSVInfo = NULL;
	m_nLevelUpMoney = 0;
	m_nTargetCount = 0;
	m_nRoundCount = 0;
	m_nSuccessRate = 0;
	m_nConsumeHPRate = 0;
	LOGGER_INFO("Skill:%p,m_nSkillId:%d",this,m_nSkillId);
}

Skill::Skill(SkillId nSkillId)
{
	m_nSkillId = nSkillId;
	m_pSkillCSVInfo = NULL;
	m_nLevelUpMoney = 0;
	m_nTargetCount = 0;
	m_nRoundCount = 0;
	m_nSuccessRate = 0;
	m_nConsumeHPRate = 0;
	LOGGER_INFO("Skill(SkillId nSkillId):%p,m_nSkillId:%d",this,m_nSkillId);
}
Skill::~Skill()
{
	LOGGER_INFO("~Skill:%p,m_nSkillId:%d",this,m_nSkillId);
}
void Skill::SetSkillInfo(SkillInfo& info)
{
	m_stSkillInfo = info;
}
void Skill::SetSkillCSVInfo(SkillCSVInfo* pCSVInfo)
{
	m_pSkillCSVInfo = pCSVInfo;
}
void Skill::Update(Player* pPlayer)
{
	if(pPlayer == NULL)
		return;
	SkillInfo& info = GetSkillInfo();

	std::string path = singleton<GameServer>::instance().GetServerPath();
	std::string filename = path + "/lua/player.lua";

	Script* pScript = singleton<ScriptManager>::instance().GetPlayerScript(filename);
	if(pScript == NULL)
		return;
	m_nLevelUpMoney = 0;
	Int32 nLevelUpMoney = pPlayer->luaCallFunction2(pScript,"getSkillLevelUpMoney",info.csv_id,info.level);
	if(nLevelUpMoney < 0)
	{
		return;
	}
	m_nLevelUpMoney = nLevelUpMoney;
	m_nTargetCount = 0;
	pScript = singleton<ScriptManager>::instance().GetSkillScript(info.csv_id);
	if(pScript != NULL)
	{
		m_nTargetCount = pScript->CallFunction2("getTargetCount",pPlayer->m_nLevel,info.level);
		if(m_nTargetCount < 0)m_nTargetCount = 0;

		m_nRoundCount = pScript->CallFunction2("getRoundCount",pPlayer->m_nLevel,info.level);
		if(m_nRoundCount < 0)m_nRoundCount = 0;

		m_nSuccessRate = pScript->CallFunction2("getSuccessRate",pPlayer->m_nLevel,info.level);
		if(m_nSuccessRate < 0)m_nSuccessRate = 0;

		m_nConsumeHPRate = pScript->CallFunction2("getConsumeHPRate",pPlayer->m_nLevel,info.level);
		if(m_nConsumeHPRate < 0)m_nConsumeHPRate = 0;


		//m_nRoundCount = 0;
		//m_nSuccessRate = 0;
		//m_nConsumeHPRate = 0;
		//LOGGER_INFO("RoundPlay,useSkill,nRet:%d",nRet);
	}
}